package com.air.controller;

import com.air.vo.query.UserLoginDto;
import com.air.domain.User;
import com.air.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author shent
 */
@RestController
@RequestMapping("user")
//@CrossOrigin(origins = {"http://localhost:9528", "null"})
public class UserController {
    @Autowired
    UserService userService;

    @PostMapping("register")
    public long register(@RequestBody User user) {
        return userService.register(user);
    }

    @PostMapping("login")
    public Map<String, Object> login(@RequestBody UserLoginDto user) {
        Map<String, Object> map = new HashMap<>(3);
        Map<String, String> token = new HashMap<>(3);
        token.put("token", "admin-token");
        map.put("code", 20000);
        map.put("data", token);
        return map;
    }

    @PostMapping("logout")
    public Map<String, Object> logout() {
        Map<String, Object> map = new HashMap<>(3);
        map.put("code", 20000);
        map.put("data", "success");
        return map;
    }

    @GetMapping("info")
    public Map<String, Object> userInfo(String token) {
        Map<String, Object> map=new HashMap<>(16);
        Map<String, Object> data = new HashMap<>(16);
        Map<String, Object> role = new HashMap<>(16);
        String[] roles = new String[1];
        roles[0] = "admin";
        role.put("roles", roles);
        role.put("introduction", "I am a super administrator");
        role.put("avatar", "https://static01.imgkr.com/temp/9a86b52b5f124900a8bd2064bffe305d.png");
        role.put("name", "Super Admin");
        data.put(token, role);
        map.put("data",data);
        map.put("code",20000);
        return map;
    }


}
